/**
 * Created by li on 2017/2/5.
 */

var InputController = cc.Class.extend({

    keyLeft:0,
    keyRight:0,
    keyUp:0,


    ctor:function(){
        this.addKeyboardEvent();

    },
    addKeyboardEvent:function(){
        var self = this;
        var eventListener = cc.EventListener.create({
            event:cc.EventListener.KEYBOARD,
            onKeyPressed:function(keycode) {
                self.setKeyValue(keycode, 1);
            },
            onKeyReleased:function(keycode){
                self.setKeyValue(keycode,0);
            },
        });

        cc.eventManager.addListener(eventListener,1);
    },
    KeyPressed:function(keycode){

        this.setKeyValue(keycode,1);
    },
    KeyReleased:function(keycode){
        this.setKeyValue(keycode,0);
    },
    setKeyValue:function(keycode,done){
        switch (keycode){
            case 38:{
                this.keyUp = done;
                break;
            }
            case 37:{
                this.keyLeft = done;
                break;
            }
            case 39:{
                this.keyRight = done;
                break;
            }
        }
    },

});